<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: yangweijie <yangweijiester@gmail.com> <code-tech.diandian.com>
// +----------------------------------------------------------------------

namespace App\Controller;
use Think\Controller;
use OT;
use User\Api\UserApi;
class AppController extends Controller{
    //后台控制器初始化
	 public function login($nickname=null,$password=null){
		$member = D("Member");
		if(IS_POST){

			$data['nickname']=I("nickname");
			$data['password']=I("password");
			$list=$member->where($data)->find();
			if($list['uid']){ //UC登录成功(账号密码验证成功)
				$data['success'] = true;
				$data['msg']     = '登陆成功';
				
				 $this->ajaxReturn($data);
			} else { //登录失败
				$data['success'] = false;
				$data['msg']     = '登陆失败！！！';
				$this->ajaxReturn($data);
			}
	
		} else {
			$data['success'] = false;
			$data['msg']     = '请使用GET方法登陆';
			$this->ajaxReturn($data);
		}
	} 
	
/* public function login($username = null, $password = null){
        if(IS_GET){

            // 调用UC登录接口登录 
            $User = new UserApi;
            $uid = $User->login($username, $password);
            $member = D("Ucenter_Member");
            $user = $member->find($uid);
            dump($user);
            if(0 < $uid){ //UC登录成功(账号密码验证成功)
                $data['success'] = true;
                $data['msg']     = '登陆成功';
                $data['obj'] = $user;
                $this->ajaxReturn($data);
            } else { //登录失败

                switch($uid) {
                    case -1: $error = '用户不存在或被禁用！'; break; //系统级别禁用
                    case -2: $error = '密码错误！'; break;
                    default: $error = '未知错误！'; break; // 0-接口参数错误（调试阶段使用）
                }
                $data['success'] = false;
                $data['msg']     = $error;
                $this->ajaxReturn($data);
            }

        } else {
            $data['success'] = false;
            $data['msg']     = '请使用GET方法登陆';
            $this->ajaxReturn($data);
        }
  } */
	
	public function zhanhui(){
		$zhanhui = M(tb_exhinf);		
		$sql = 'SELECT * FROM duijie_tb_exhinf;';
		$list = $zhanhui -> query($sql);
		if($list){
			$data['success']  = true;
			$data['msg']      = '获取成功';
			$data['rows']     = $list;
		
		}else{
			$data['success'] = false;
			$data['msg']     = '获取失败';
		}
		$this->ajaxReturn($data,'JSON');
	}
	
	public function tecach(){
		$tecach	=	M('TbTecach');
		$list=$tecach->join('duijie_tb_teccoo on duijie_tb_tecach.hztype=duijie_tb_teccoo.cid')
		->join('duijie_tb_teccsd on duijie_tb_tecach.csd=duijie_tb_teccsd.sid')
		->field('duijie_tb_tecach.*,duijie_tb_teccsd.csd,duijie_tb_teccoo.cootype')
		->select();
		//int_to_string($list,array('djstatus'=>array(0=>'未对接',1=>'对接中',2=>'已对接')));              //数字转为字符串
		//$tID = array_column($list,"tID");
		
		foreach ($list as $key => $value) {
			$str=$list[$key]['tID'];
			$map['id']=array('in',$str);
			$list[$key]['tids']=M("TbLable")->where($map)->select();
			
		}
		foreach ($list as $key => $value) {
			$str1=$list[$key]['labfid'];
			$str2=$list[$key]['labkid'];
			$map1['ID']=$str1;
			$map2['ID']=$str2;
			$list[$key]['tids1']=M("TbTeclab")->where($map1)->select();
			$list[$key]['tids2']=M("TbTeclab")->where($map2)->select();
		}
// 		int_to_string($list,$map = array('tID'=>array(1=>'技术创新')));
		//dump($list);
		$data['success']  = true;
		$data['msg']      = '获取成功';
		$data['rows']     = $list;
		$this->ajaxReturn($data,'JSON');		
	}
	
	public function  tecdem(){
		$dem = M('TbDemand');
		$xname=I('xname','','text');		
		$map['rid'] = UID;
		if ($xname !== '') {
			$map['xname'] = array('like', '%' . (string)$xname . '%');
		}
		$sql='SELECT d.*,t.fplace,t.place FROM duijie_tb_demand d,duijie_tb_tecdem t
            WHERE  d.rid = t.id';
		$list=$dem->where($map)->query($sql);

		//int_to_string($list,array('xdstatus'=>array(-1=>'未对接',0=>'对接中',1=>'对接已结束')));              //数字转为字符串
			
		foreach ($list as $key => $value) {
			$str=$list[$key]['jsbq'];
			$mapp['id']=array('in',$str);
			$list[$key]['tids']=M("TbLable")->where($mapp)->select();
		}
			
		foreach ($list as $key => $value) {
			$str1=$list[$key]['fplace'];
			$str2=$list[$key]['place'];
			$map1['id']=array('in',$str1);
			$map2['id']=array('in',$str2);
			$list[$key]['tids1']=M("District")->where($map1)->select();
			$list[$key]['tids2']=M("District")->where($map2)->select();
		}
			
		foreach ($list as $key => $value){
			$str3=$list[$key]['ffield'];
			$str4=$list[$key]['field'];
			$map3['ID']=array('in',$str3);
			$map4['ID']=array('in',$str4);
			$list[$key]['tids3']=M("TbTeclab")->where($map3)->select();
			$list[$key]['tids4']=M("TbTeclab")->where($map4)->select();
		}

		$data['success']  = true;
		$data['msg']      = '获取成功';
		$data['rows']     = $list;
		$this->ajaxReturn($data,'JSON');
	}
	/* 未开始 */
	public function exhinf(){
	
		$zhanhui = M(tb_exhinf);
		$map['zstatus'] = array('eq', 0);
		$sql = 'SELECT * FROM duijie_tb_exhinf where duijie_tb_exhinf.zstatus=0;';
		$list = $zhanhui -> where($map) -> query($sql);
		$data['success']  = true;
		$data['msg']      = '获取成功';
		$data['rows']     = $list;
		$this->ajaxReturn($data,'JSON');
	}
	/* 进行中 */
	public function exhing(){
	
		$zhanhui = M(tb_exhinf);
		//$map['zstatus'] = array('eq', 1);
		$sql = 'SELECT * FROM duijie_tb_exhinf where duijie_tb_exhinf.zstatus=1;';
		$list = $zhanhui -> query($sql);
 		$data['success']  = true;
 		$data['msg']      = '获取成功';
 		$data['rows']     = $list;
 		$this->ajaxReturn($data,'JSON');
    //    dump($list);
	}
	/* 已结束 */
	public function exhend(){
	
		$zhanhui = M(tb_exhinf);
	//	$map['zstatus'] = array('eq',2);
		$sql = 'SELECT * FROM duijie_tb_exhinf  where duijie_tb_exhinf.zstatus=2;';
		$list = $zhanhui  -> query($sql);
		$data['success']  = true;
		$data['msg']      = '获取成功';
		$data['rows']     = $list;
		$this->ajaxReturn($data,'JSON');
	}
}    